package cn.cleanarch.infra.idp.pms.constants;

/**
 * 缓存和存储相关常量定义
 */
public final class StorageConstants {

    /**
     * 设计文件
     */
    public static final String BUSINESS_TYPE_DESIGN_FILE = "DESIGN_FILE";
    /**
     * 用户信息
     */
    public static final String BUSINESS_TYPE_USER_INFO = "USER_INFO";

    private StorageConstants() {
        // 防止实例化
    }

    // 文件存储相关
    public static final String S3_BUCKET_NAME = "idp";
    public static final String S3_BASE_PATH = "idp-design-file/";
    public static final String S3_ENDPOINT = "http://localhost:9000";
    public static final String S3_ACCESS_KEY = "admin";
    public static final String S3_SECRET_KEY = "P@88w0rd";

    // 解压目录
    public static final String EXTRACT_BASE_PATH = System.getProperty("user.home") + "/idp-design-file-extract";

    // 临时文件路径
    public static final String TEMP_EXTRACT_PATH_PREFIX = "temp/extract/";
    public static final String TEMP_UPLOAD_PATH_PREFIX = "temp/upload/";

    // 文件命名规则
    public static final String FILE_NAME_SEPARATOR = "_";
    public static final String FILE_NAME_TIMESTAMP_FORMAT = "yyyyMMddHHmmss";
    public static final String FILE_KEY_TIMESTAMP_FORMAT = "yyyyMMddHHmmssSSS";

    // 缓存配置
    public static final long EXTRACT_CACHE_MAX_AGE = 24 * 60 * 60 * 1000; // 24小时
    public static final int EXTRACT_LOCK_TIMEOUT_SECONDS = 5; // 5秒
    public static final int CLEANUP_INTERVAL_MINUTES = 60; // 1小时清理一次

    // 缓冲区大小
    public static final int DEFAULT_BUFFER_SIZE = 8192;
    public static final int LARGE_BUFFER_SIZE = 16384;
    public static final int SMALL_BUFFER_SIZE = 4096;

    // 文件大小限制
    public static final long MAX_FILE_SIZE_BYTES = 100 * 1024 * 1024; // 100MB
    public static final long MAX_TOTAL_SIZE_BYTES = 1024 * 1024 * 1024; // 1GB
    public static final int MAX_FILES_PER_BATCH = 50;

    // 解压限制
    public static final long MAX_EXTRACTED_SIZE = 50 * 1024 * 1024; // 50MB
    public static final int MAX_EXTRACTED_FILES = 1000;
    public static final int MAX_EXTRACT_DEPTH = 3; // 最大解压深度

    // 文件扩展名白名单（安全检查）
    public static final String[] ALLOWED_IMAGE_EXTENSIONS = {
        ".jpg", ".jpeg", ".png", ".gif", ".svg", ".webp", ".bmp", ".ico"
    };
    public static final String[] ALLOWED_DOCUMENT_EXTENSIONS = {
        ".html", ".htm", ".css", ".js", ".txt", ".md"
    };
    public static final String[] ALLOWED_FONT_EXTENSIONS = {
        ".woff", ".woff2", ".ttf", ".eot", ".otf"
    };

    // 文件类型白名单（危险扩展名）
    public static final String[] DANGEROUS_EXTENSIONS = {
        ".exe", ".bat", ".cmd", ".com", ".pif", ".scr", ".vbs", ".js", ".jar", ".sh"
    };

    // Content-Disposition 头部值
    public static final String CONTENT_DISPOSITION_INLINE = "inline";
    public static final String CONTENT_DISPOSITION_ATTACHMENT = "attachment";

    // HTTP状态码
    public static final int HTTP_STATUS_OK = 200;
    public static final int HTTP_STATUS_NOT_FOUND = 404;
    public static final int HTTP_STATUS_FORBIDDEN = 403;
    public static final int HTTP_STATUS_BAD_REQUEST = 400;
    public static final int HTTP_STATUS_INTERNAL_ERROR = 500;
    public static final int HTTP_STATUS_FILE_TOO_LARGE = 413;
    public static final int HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415;

    // 缓存控制
    public static final String CACHE_CONTROL_PUBLIC = "public, max-age=3600";
    public static final String CACHE_CONTROL_PRIVATE = "private, max-age=0, no-cache, no-store";
    public static final String CACHE_CONTROL_NO_CACHE = "no-cache";
    public static final String ETAG_HEADER = "ETag";
    public static final String IF_NONE_MATCH_HEADER = "If-None-Match";
    public static final String LAST_MODIFIED_HEADER = "Last-Modified";
    public static final String IF_MODIFIED_SINCE_HEADER = "If-Modified-Since";
    public static final String CACHE_CONTROL_HEADER = "Cache-Control";

    // 默认值
    public static final String DEFAULT_CHARSET = "UTF-8";
    public static final String DEFAULT_MIME_TYPE = "application/octet-stream";
    public static final String INDEX_HTML_FILE = "index.html";
    public static final String FAVICON_ICO_FILE = "favicon.ico";

    // 重试配置
    public static final int MAX_RETRY_ATTEMPTS = 3;
    public static final long RETRY_DELAY_MS = 1000;
    public static final long RETRY_BACKOFF_MULTIPLIER = 2;
}